package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class AccordionTag extends BodyTagSupport {

	private String idAccordion;
	private String form;
	private String active;
	private String collapsible;
	private String animate;
	private String header;
	private String heightStyle;
	private String iconHeader;
	private String iconActiveHeader;
	private String event;
	
	/************** Item Accordion ***************/
	private String corpoItemAccordion;
	

	@Override
	public int doEndTag() throws JspException {

		// AQUI VOC~E PEGA O CORPO INTEIRO - SERÁ UM INCLUDE
		//
		String corpoAccordion = getBodyContent().getString();


		// PAGECONTEXT É PROTECTED
		JspWriter saida = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("idAccordion", idAccordion);
		request.setAttribute("bodyAccordion", corpoAccordion);
		request.setAttribute("form", form);
		request.setAttribute("active", active);
		request.setAttribute("collapsible", collapsible);
		request.setAttribute("animate", animate);
		request.setAttribute("header", header);
		request.setAttribute("iconHeader", iconHeader);
		request.setAttribute("iconActiveHeader", iconActiveHeader);
		request.setAttribute("heightStyle", heightStyle);
		request.setAttribute("event", event);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);

		// APÓS A EXECUÇÃO ELE IRÁ INTERPRETAR A SAIDA
		responseWrapper.getString();

		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/accordion/accordion.jsp");

		try {

			req.include(request, responseWrapper);

			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);

		} catch (IOException e1) {

			e1.printStackTrace();

		} catch (ServletException e1) {

			e1.printStackTrace();

		}

		return super.doEndTag();
	}

	// ************************************* GET AND SET *******************************/
	
	
	
	public String getIdAccordion() {
		return idAccordion;
	}

	public String getForm() {
		return form;
	}

	public void setForm(String form) {
		this.form = form;
	}

	public void setIdAccordion(String idAccordion) {
		this.idAccordion = idAccordion;
	}
	
	public String getActive() {
		return active;
	}

	public void setActive(String active) {
		this.active = active;
	}

	public String getAnimate() {
		return animate;
	}

	public void setAnimate(String animate) {
		this.animate = animate;
	}
	
	public String getCollapsible() {
		return collapsible;
	}

	public void setCollapsible(String collapsible) {
		this.collapsible = collapsible;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}
	
	public String getHeightStyle() {
		return heightStyle;
	}

	public void setHeightStyle(String heightStyle) {
		this.heightStyle = heightStyle;
	}
	
	public String getIconHeader() {
		return iconHeader;
	}

	public void setIconHeader(String iconHeader) {
		this.iconHeader = iconHeader;
	}

	public String getIconActiveHeader() {
		return iconActiveHeader;
	}

	public void setIconActiveHeader(String iconActiveHeader) {
		this.iconActiveHeader = iconActiveHeader;
	}

	public String getEvent() {
		return event;
	}

	public void setEvent(String event) {
		this.event = event;
	}

	public String getCorpoItemAccordion() {
		return corpoItemAccordion;
	}

	public void setCorpoItemAccordion(String corpoItemAccordion) {
		this.corpoItemAccordion = corpoItemAccordion;
	}


}
